package learn.spring.event;

import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import learn.spring.Timer;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * 监听器
 * 
 * @author PinWei Wan
 * @since 2.6.9
 */
@Slf4j
@Component
public class OrderProductListener implements ApplicationListener<OrderProductEvent> {
    /** 使用 onApplicationEvent 方法对消息进行接收处理 */
    @SneakyThrows
    @Override
    public void onApplicationEvent(OrderProductEvent event) {
        String orderId = event.getOrderId();

        // 模拟业务处理
        long cost = Timer.mock();

        log.info("{} 同步任务处理完成, 耗时{}毫秒", orderId, cost);
    }
}
